<template>
  <div class="train-item" @click="$router.push(`/train/${id}`)">
    <div class="img">
      <img :src="`https://file.ituring.com.cn/SmallCover/${coverKey}`" alt="" />
    </div>
    <div class="train-item-right">
      <h3 class="train-title">{{ name }}</h3>
      <p class="train-detail">
        {{ teacherName }} · {{ classHour }}课时 · {{ userCount }}参与
      </p>
      <span class="train-tag" :class="isFree?'free':''">{{ price }}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: [
    "id",
    "coverKey",
    "name",
    "teacherName",
    "classHour",
    "userCount",
    "salePrice",
  ],
  computed: {
    price() {
      let num = parseInt(this.salePrice);
      if (num == 0) {
        // this.isFree = true
        return "免费";
      } else {
        // this.isFree = false
        return num + "元";
      }
    },
    // 
    isFree() {
      let num = parseInt(this.salePrice);
      if (num == 0) {
        return true;
      } 
      else {
        return false;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.train-item {
  margin-bottom: 10px;
  background-color: var(--train-bg-grey);
  padding: 10px;
  display: flex;
  justify-content: space-between;
  .img {
    img {
      width: 105px;
      height: 70px;
    }
  }
  .train-item-right {
    width: 200px;
    margin-left: 20px;
    .train-title {
      color: var(--book-name-font-black);
      font-size: 16px;
      line-height: 22px;
      max-height: 44px;
    }
    .train-detail {
      margin: 5px 0 0;
      color: var(--more-font-grey);
      font-size: 14px;
      line-height: 20px;
      max-height: 20px;
    }
    .train-tag {
      display: block;
      color: var(--book-name-font-black);
      font-size: 14px;
      line-height: 20px;
      margin: 5px 0 0;
      &.free {
        color: var(--tag-font-orange);
      }
    }
  }
}
</style>